﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BdClient;

namespace Univer
{
    public partial class AvailableCarsForm : Form
    {
        private readonly BdExecute _execute;
        public AvailableCarsForm()
        {
            
            _execute=new BdExecute();
            InitializeComponent();
            checkBox1.Text = _execute.GetPropertyCar().ToArray()[0].Description;
            checkBox2.Text = _execute.GetPropertyCar().ToArray()[1].Description;
            checkBox3.Text = _execute.GetPropertyCar().ToArray()[2].Description;
            checkBox4.Text = _execute.GetPropertyCar().ToArray()[3].Description;
            checkBox5.Text = _execute.GetPropertyCar().ToArray()[4].Description;
            checkBox6.Text = _execute.GetPropertyCar().ToArray()[5].Description;
            foreach (var mark in _execute.GetMarks())
            {
                comboBox1.Items.Add(mark.Name);
            }
          //  _execute.GetClient()
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {
            var table = new DataTable();
        //    table.Columns.Add("id");
            table.Columns.Add("Марка");
            table.Columns.Add("Цена");
            table.Columns.Add("Аренда в день");
            foreach (var notBusyResult in _execute.GetCarsNotBusy(dateTimePicker1.Value, dateTimePicker2.Value, Convert.ToDecimal(textBox1.Text), comboBox1.SelectedItem.ToString()))
            {
                table.Rows.Add(notBusyResult.Name, notBusyResult.Name, notBusyResult.PriceDay);
            }
            dataGridView1.DataSource = table;
        }

        private void button1_Click(object sender, EventArgs e)
        {

            var d = _execute.AddPreference(Manager.getInstance().result.id, comboBox1.SelectedIndex, dateTimePicker1.Value, dateTimePicker2.Value);
            Manager.getInstance().fineRequest = d;
            Manager.getInstance().mainFormCallback.updateFine();
            if (checkBox1.Checked) _execute.AddPreference_PropertyCars(d, 1);
            if (checkBox2.Checked) _execute.AddPreference_PropertyCars(d, 2);
            if (checkBox3.Checked) _execute.AddPreference_PropertyCars(d, 3);
            if (checkBox4.Checked) _execute.AddPreference_PropertyCars(d, 4);
            if (checkBox5.Checked) _execute.AddPreference_PropertyCars(d, 5);
            if (checkBox6.Checked) _execute.AddPreference_PropertyCars(d, 6);
            Close();
        }
    }
}
